#ifndef TEMPLE_THIRD_KEEPER_H_
#define TEMPLE_THIRD_KEEPER_H_

#include "config.h"
#include <mutex>
#include <zookeeper/zookeeper.h>

class Keeper
{
public:
	Keeper();
	~Keeper();

    struct Config
    {
        string zoo_host;
        int zoo_port;
        int timeout;
    };

	int open(const Config &conf);
	void close();

	int checkin(const string &label, const string &node);
	int resolve(const string &label, string &node);

private:
    zhandle_t *handler;
    bool connected;
    util::Logger logger;
    Config config;

    void main_watcher(int type, int state, const char *path);
    static void watcher(zhandle_t *zh, int type, int state, const char *path, void *context);

    std::mutex cache_mutex;
    std::map<string, std::vector<string>> cache_map;
};

#endif //TEMPLE_THIRD_KEEPER_H_
